<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('pay')" />
</head>
<body>
<div>
	<div class="panel panel-success panel-heading" style="background-color: #1c84c6;color: #ffffff">
		<p style="text-align: center"> checkstand </p>
	</div>
	<form id="form-India-pay">
		<div class="row" style="width: 100%">
<!--			<div class="col-sm-6">-->
			<input name="orderChildCode" id="orderChildCode" hidden="hidden"/>
			<input name="userCode" id="userCode" value="10000" hidden="hidden"/>
			<input name="callbackUrl" id="callbackUrl" value="https://www.google.com" hidden="hidden"/>
				<div class="form-group">
					<input type="text" id="pay-money" name="orderAmount" class="form-control" style="margin: 10%;width: 80%" placeholder="Please enter ₹0.00">
				</div>
				<div class="form-group">
					<select class="form-control m-b" style="margin: 10%;width: 80%" name="channelId">
<!--						<option>选项 1</option>-->
<!--						<option>选项 2</option>-->
<!--						<option>选项 3</option>-->
<!--						<option>选项 4</option>-->
						<option th:each="sysChannel : ${sysChannels}" th:text="${sysChannel.channelName}" th:value="${sysChannel.channelId}"></option>
					</select>
				</div>
<!--			</div>-->
		</div>
	</form>
	<div class="row" style="margin-left: 30%;width: 200px">
		<div class="col-sm-offset-2 col-sm-10" style="align-content: center;width: 120px">
			<button type="button" class="btn btn-w-m btn-success" onclick="submitHandler()">pay</button>
		</div>
	</div>
</div>


	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: datetimepicker-js" />
	<script th:inline="javascript">
		var prefix = ctx + "pay";


		$(function() {
			$("#orderChildCode").val(random_No());
		});

		function random_No(j) {
			var random_no = "";
			for (var i = 0; i < j; i++) //j位随机数，用以加在时间戳后面。
			{
				random_no += Math.floor(Math.random() * 10);
			}
			random_no = new Date().getTime() + random_no;
			return random_no;
		};


		//保存表单
		function submitHandler(){
			let number = $("#pay-money").val();
			number = parseInt(number);
			if (!Number.isInteger(number)) {
				$.modal.msgError("money type is not valid");
				return false;
			}
			$.ajax({
				type: "POST",
				url: prefix + "/India/testOrder" ,
				data: $('#form-India-pay').serialize() ,
				async: false,
				success: function (data) {
					$("#orderChildCode").val(random_No());
					window.location.href=data;
					// if (data.code==0) {
					// 	$.modal.msgSuccess("pay success");
					// 	$("#orderChildCode").val(random_No());
					// }else {
					// 	$.modal.msgError(data.msg);
					// }
				},
				error: function () {
					$.modal.msgError("error");
					$("#orderChildCode").val(random_No());
				}
			})
		}


	</script>
</body>
</html>